#include <stdio.h>
#include <stdint.h>
#include <errno.h>

#include <ZLog.h>
#include <HTTPLiveProxy.h>

int main(int argc, char *argv[])
{
    HttpLiveT *hl = NULL;
    int ret = 0, ret1;
    char *mediaIn = NULL;
    FILE *in;
    char buf[1024] = {0};
    
    Z_ASSERT(argc == 2);
    mediaIn = argv[1];
    hl = HLCreate(8090, 0, "xxxx.ts");

    Z_ASSERT(hl);

    ret = HLStart(hl);
    Z_ASSERT(ret == 0);

    in = fopen(mediaIn, "r");
    
    while (1)
    {
        ret = fread(buf, 1, 1024, in);
        if (ret > 0)
        {
//            LogD("fill buffer, buf, size(%d)", ret);
            ret1 = HLFill(hl, buf, ret);
            Z_ASSERT(ret);
        }
        else
        {
            LogE("fread failure... errno(%d).", errno);
            break;
        }
        usleep(500);
    }

    HLDestroy(hl);
    return 0;
    
}

